package com.example.myapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.myapplication.R;

import java.util.List;
import java.util.Map;

public class MyListAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mlayoutInflater;
    private List<Map> lm;

    MyListAdapter(Context mContext ){


        this.mContext = mContext;
        this.mlayoutInflater = LayoutInflater.from(mContext);
    }
    public MyListAdapter(Context mContext, List<Map> ls){

        this.mContext = mContext;
        this.mlayoutInflater = LayoutInflater.from(mContext);
        this.lm = ls;
    }
    @Override
    //列表长度
    public int getCount() {
        return lm.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    static class MyListAdapterIndex{
        private TextView tv1,tv2,tv3,tv4,tv5;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyListAdapterIndex myListAdapterIndex = null;

        if(myListAdapterIndex == null){
            convertView = mlayoutInflater.inflate(R.layout.activity_index, null);
            myListAdapterIndex = new MyListAdapterIndex();
            myListAdapterIndex.tv1 = convertView.findViewById(R.id.tv1);
            myListAdapterIndex.tv2 = convertView.findViewById(R.id.tv2);
            myListAdapterIndex.tv3 = convertView.findViewById(R.id.tv3);
            myListAdapterIndex.tv4 = convertView.findViewById(R.id.tv4);
            myListAdapterIndex.tv5 = convertView.findViewById(R.id.tv5);
            convertView.setTag(myListAdapterIndex);
        }else {
            myListAdapterIndex = (MyListAdapterIndex) convertView.getTag();
        }
//        myListAdapterIndex.tv1.setText("1");
//        myListAdapterIndex.tv2.setText("2");
//        myListAdapterIndex.tv3.setText("3");
//        myListAdapterIndex.tv4.setText("4");
//        myListAdapterIndex.tv5.setText("5");
        myListAdapterIndex.tv1.setText(lm.get(position).get("id").toString());
        myListAdapterIndex.tv2.setText(lm.get(position).get("name").toString());
        myListAdapterIndex.tv3.setText(lm.get(position).get("age").toString());
        myListAdapterIndex.tv4.setText(lm.get(position).get("create_time").toString());
        myListAdapterIndex.tv5.setText(lm.get(position).get("update_time").toString());
        return  convertView;
    }

}
